<?php 
/* ================================================================================
 * Living Web	 
 *
 * main.php: This is the main file for Living Web.
 *
 * Author: Eric Hendrickson (enhendrickson@liberty.edu)
 * Date: 2/18/05
   ================================================================================ */
	
	global $SSO, $Security, $AppID, $User, $DB;
	
	//Check to see if there is a valid session 
	$SessionInfo = $SSO->isValidSession("index.php?action=login", $SSO->getSessionInformation());	
		
	//Check to see if the user has rights to be on LivingWeb
	$PageRights = array('ADMIN', 'USER');
	$UserRoles = $Security->ValidateUser($SessionInfo['username'], $AppID, $PageRights, 1);
	
	//Grab the user info
	$UserInfo = $User->GetUserInfo($SessionInfo['username']);	

	if(isset($_COOKIE['MID']))
	{
		setcookie("MID", "",false,"/");
	}
?>
<table cellpadding="0" cellspacing="0" width="100%" border="0">
	<tr>
		<td align="right" valign="top">
			<form action="index.php" name="frmQuickJump" method="get" style="padding:0 0 0 0;margin:0 0 0 0;">
			<table cellpadding="0" cellspacing="0" border="0">
				<tr>
					<td><span class="T1">Quick Jump to PID</span></td>
					<td><span class="T1">&nbsp;&nbsp;</span></td>
					<td><input name="PID" type="text" size="5" class="T1"></td>
					<td><input name="action" type="hidden" value="edit"><span class="T1">&nbsp;&nbsp;</span></td>
					<td><input name="Jump" type="submit" value="Jump" class="B0"></td>
				</tr>
			</table>
			</form>
		</td>
	</tr>
	<tr>
		<td><br></td>
	</tr>
	<tr>
		<td>
			<table cellpadding="0" cellspacing="0" align="center" width="70%">
				<tr bgcolor="#D8DA85">
					<td style="border-bottom:1px solid #000000;"><span class="TB2">&nbsp;Ministries</span></td>
					<td style="border-bottom:1px solid #000000;" valign="middle" align="right">
						<table cellpadding="3" cellspacing="3">
							<tr>
								<td><span class="T1">&nbsp;</span></td>
							</tr>
						</table>
					</td>
				</tr>
			<?php
				if(in_array("ADMIN",$UserRoles))
				{
					$DB->query("SELECT MinistryID, MinistryName FROM ministries ORDER BY MinistryName");
					while($row = $DB->fetch_row())
					{
						print '<tr><td style="border-bottom:1px solid #000000;"><span class="T1">&nbsp;&nbsp;' . $row['MinistryName'] . '</span></td>';
						print '<td style="border-bottom:1px solid #000000;" valign="middle" align="right">
											<table cellpadding="3" cellspacing="3">
												<tr>
													<td>
														<a class="L0" href="index.php?action=menu_by_div&amp;div_code=' . $row['MinistryID'] . '">Edit Menu</a></td>
													<td>
														<span class="T0">|</span></td>
													<td>
														<a class="L0" href="index.php?action=pages_by_div&amp;div_code=' . $row['MinistryID'] . '">View Pages</a></td>
												</tr>
											</table>
										</td></tr>';
					}
				}
				else
				{
					$div_codes = split(',',$UserInfo['div_codes']);	
					if(trim($div_codes[0]) == '')
					{	
						array_pop($div_codes);
					}
					if(count($div_codes) <= 0)
					{
						print '<tr><td colspan="2" style="border-bottom:1px solid #000000;"><span class="T1" style="color:red;"><em>You do not have access to any ministries.  Contact your adminsitrator if you believe this to be an error.</em></span></td></tr>';
					}
					else
					{
						sort($div_codes);
						global $DB;
						foreach($div_codes as $code)
						{
							$DB->query("SELECT MinistryID, MinistryName FROM ministries WHERE MinistryID = '" . $code . "'");
							$row = $DB->fetch_row();
							print '<tr><td style="border-bottom:1px solid #000000;"><span class="T1">&nbsp;&nbsp;' . $row['MinistryName'] . '</span></td>';
							print '<td style="border-bottom:1px solid #000000;" valign="middle" align="right">
												<table cellpadding="3" cellspacing="3">
													<tr>
														<td>
															<a class="L0" href="index.php?PID='.$_GET['PID'].'&amp;action=menu_by_div&amp;div_code=' . $row['MinistryID'] . '">Edit Menu</a></td>
														<td>
															<span class="T0">|</span></td>
														<td>
															<a class="L0" href="index.php?PID='.$_GET['PID'].'&amp;action=pages_by_div&amp;div_code=' . $row['MinistryID'] . '">View Pages</a></td>
													</tr>
												</table>
											</td></tr>';
						}
					}
				}
			?>
			</table>
		</td>
	</tr>
</table>